package Server.ExtComponents.MinaEngine.service;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * @author :石头哥哥<br/>
 *         Project:FrameServer1.0
 *         Date: 13-5-17
 *         Time: 下午10:31
 *         1.缓存游戏业务数据;
 *         2.管理玩家状态;
 */
public class ObjectSession extends ConcurrentLinkedQueue<IoBuffer>{
     private IoSession session;//底层channel管理


     public ObjectSession(IoSession session){
        this.session=session;
     }

    /**
     * 添加decode的buffer数据到缓存队列
     * @param buffer
     * @return
     */
    public boolean addByteBuf(IoBuffer buffer) {
        return super.add(buffer);
    }

    /**
     * 处理缓存队列数据
     * @return
     */
    public IoBuffer poolByteBuf(){
        return super.poll();
    }

    /**
     * isEmpty
     * @return
     */
    @Override
    public boolean isEmpty(){
        return super.isEmpty();
    }

    /**
     * release
     */
    public void  clear(){
        super.clear();
        session.close(true);
    }


    public IoSession getSession(){
        return session;
    }

}
